<html>
<!-- =====================================================================

  File:      Generated file for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     June 16, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) 2003 Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
<head>
  <link rel=stylesheet href=style.css>
</head>
<body>
<div class=SourcePanel style="font-size:12">
<pre style="background-color:white">
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Collections</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">ComponentModel</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Data</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Drawing</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">Security</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">WebControls</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">HtmlControls</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Text</span><span style="color: #4444FF">;</span>

<span style="color: #008000">/* =====================================================================

  File:      Register.aspx.cs for Adventure Works Cycles Storefront Sample
  Summary:   Allows the user to create a new login
  Date:	     June 16, 2003

---------------------------------------------------------------------

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= */</span>

<span style="color: #0000FF"><strong>namespace</strong></span> <span style="color: #2040a0">Microsoft</span>.<span style="color: #2040a0">Samples</span>.<span style="color: #2040a0">SqlServer</span> <span style="color: #4444FF"><strong>{</strong></span>

    <span style="color: #0000FF"><strong>public</strong></span> <span style="color: #2040a0">partial</span> <span style="color: #0000FF"><strong>class</strong></span> <span style="color: #2040a0">Register</span> <span style="color: #4444FF">:</span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">Page</span>
    <span style="color: #4444FF"><strong>{</strong></span>

    
<span style="color: #008000">//         public Register() {</span>
<span style="color: #008000">//             Page.Init += new System.EventHandler(Page_Init);</span>
<span style="color: #008000">//         }</span>

        <span style="color: #008000">//*******************************************************</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">// The RegisterButton_Click event handler is used on this page to</span>
        <span style="color: #008000">// add a new user into the AdventureWorks Customers database.</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">// The event handler then migrates any items stored in the user's</span>
        <span style="color: #008000">// temporary (non-persistent) shopping cart to their</span>
        <span style="color: #008000">// permanent customer account, adds a cookie to the client</span>
        <span style="color: #008000">// (so that we can personalize the home page's welcome</span>
        <span style="color: #008000">// message), and then redirects the browser back to the</span>
        <span style="color: #008000">// originating page.</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">//*******************************************************</span>

        <span style="color: #0000FF"><strong>protected</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">RegisterButton_Click</span><span style="color: #4444FF">(</span><span style="color: #2040a0">object</span> <span style="color: #2040a0">sender</span>, <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">ImageClickEventArgs</span> <span style="color: #2040a0">e</span><span style="color: #4444FF">)</span>
        <span style="color: #4444FF"><strong>{</strong></span>
            <span style="color: #008000">// Only attempt a login if all form fields on the page are valid</span>
            <span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">Page</span>.<span style="color: #2040a0">IsValid</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>true</strong></span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>

                <span style="color: #008000">// Store off old temporary shopping cart ID</span>
                <span style="color: #2040a0">ShoppingCartDB</span> <span style="color: #2040a0">shoppingCart</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">ShoppingCartDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
                <span style="color: #2040a0">String</span> <span style="color: #2040a0">tempCartId</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">shoppingCart</span>.<span style="color: #2040a0">GetShoppingCartId</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

                <span style="color: #008000">// Add New Customer to CustomerDB database</span>
                <span style="color: #2040a0">CustomersDB</span> <span style="color: #2040a0">accountSystem</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">CustomersDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
				<span style="color: #2040a0">try</span> 
				<span style="color: #4444FF"><strong>{</strong></span>
					<span style="color: #2040a0">String</span> <span style="color: #2040a0">customerId</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">accountSystem</span>.<span style="color: #2040a0">AddCustomer</span><span style="color: #4444FF">(</span>
						<span style="color: #2040a0">SettingsControl</span>.<span style="color: #2040a0">FirstNameText</span>, <span style="color: #2040a0">SettingsControl</span>.<span style="color: #2040a0">LastNameText</span>, <span style="color: #2040a0">SettingsControl</span>.<span style="color: #2040a0">EmailText</span>,
						<span style="color: #2040a0">SettingsControl</span>.<span style="color: #2040a0">PasswordText</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

					<span style="color: #008000">// Set the user's authentication name to the customerId</span>
					<span style="color: #2040a0">FormsAuthentication</span>.<span style="color: #2040a0">SetAuthCookie</span><span style="color: #4444FF">(</span><span style="color: #2040a0">customerId</span>, <span style="color: #0000FF"><strong>false</strong></span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

					<span style="color: #008000">// Migrate any existing shopping cart items into the permanent shopping cart</span>
					<span style="color: #2040a0">shoppingCart</span>.<span style="color: #2040a0">MigrateCart</span><span style="color: #4444FF">(</span><span style="color: #2040a0">tempCartId</span>, <span style="color: #2040a0">customerId</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

					<span style="color: #008000">// Store the user's fullname in a cookie for personalization purposes</span>
					<span style="color: #2040a0">String</span> <span style="color: #2040a0">fullName</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">SettingsControl</span>.<span style="color: #2040a0">FirstNameText</span> <span style="color: #4444FF">+</span> <span style="color: #444444">&quot; &quot;</span> <span style="color: #4444FF">+</span>
					  <span style="color: #2040a0">SettingsControl</span>.<span style="color: #2040a0">LastNameText</span><span style="color: #4444FF">;</span>

					<span style="color: #008000">//We need to Base64 this unicode string because cookies do not support unicode characters.</span>
					<span style="color: #2040a0">UnicodeEncoding</span> <span style="color: #2040a0">unicode</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">UnicodeEncoding</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

					<span style="color: #2040a0">Response</span>.<span style="color: #2040a0">Cookies</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;AdventureWorks_FullName&quot;</span><span style="color: #4444FF">]</span>.<span style="color: #2040a0">Value</span> <span style="color: #4444FF">=</span>
					  <span style="color: #2040a0">Convert</span>.<span style="color: #2040a0">ToBase64String</span><span style="color: #4444FF">(</span><span style="color: #2040a0">unicode</span>.<span style="color: #2040a0">GetBytes</span><span style="color: #4444FF">(</span><span style="color: #2040a0">fullName</span><span style="color: #4444FF">)</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

					<span style="color: #2040a0">SettingsControl</span>.<span style="color: #2040a0">OnAccountSettingsUpdate</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

					<span style="color: #008000">// Redirect browser back to shopping cart page</span>
					<span style="color: #2040a0">Response</span>.<span style="color: #2040a0">Redirect</span><span style="color: #4444FF">(</span><span style="color: #444444">&quot;Demographics.aspx&quot;</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
				<span style="color: #4444FF"><strong>}</strong></span>
				<span style="color: #0000FF"><strong>catch</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">UserAlreadyExistsException</span><span style="color: #4444FF">)</span> 
				<span style="color: #4444FF"><strong>{</strong></span>
					<span style="color: #2040a0">SettingsControl</span>.<span style="color: #2040a0">ErrorMessage</span> <span style="color: #4444FF">=</span> <span style="color: #444444">&quot;Registration failed:&amp;nbsp; That email address is already registered.&lt;br&gt;&lt;img align=left height=1 width=92 src=images/1x1.gif&gt;&quot;</span><span style="color: #4444FF">;</span>
				<span style="color: #4444FF"><strong>}</strong></span>
            <span style="color: #4444FF"><strong>}</strong></span>
        <span style="color: #4444FF"><strong>}</strong></span>
        
        <span style="color: #0000FF"><strong>private</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">Page_Load</span><span style="color: #4444FF">(</span><span style="color: #2040a0">object</span> <span style="color: #2040a0">sender</span>, <span style="color: #2040a0">System</span>.<span style="color: #2040a0">EventArgs</span> <span style="color: #2040a0">e</span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>
            <span style="color: #008000">// Put user code to initialize the page here</span>
        <span style="color: #4444FF"><strong>}</strong></span>

        <span style="color: #0000FF"><strong>private</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">Page_Init</span><span style="color: #4444FF">(</span><span style="color: #2040a0">object</span> <span style="color: #2040a0">sender</span>, <span style="color: #2040a0">EventArgs</span> <span style="color: #2040a0">e</span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>
            <span style="color: #008000">//</span>
            <span style="color: #008000">// CODEGEN: This call is required by the ASP.NET Web Form Designer.</span>
            <span style="color: #008000">//</span>
            <span style="color: #2040a0">InitializeComponent</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
        <span style="color: #4444FF"><strong>}</strong></span>

<span style="color: #0000ff"><strong>		#region Web Form Designer generated code</strong></span>
        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">/// Required method for Designer support - do not modify</span>
        <span style="color: #008000">/// the contents of this method with the code editor.</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        <span style="color: #0000FF"><strong>private</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">InitializeComponent</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>    
			<span style="color: #0000FF"><strong>this</strong></span>.<span style="color: #2040a0">RegisterButton</span>.<span style="color: #2040a0">Click</span> <span style="color: #4444FF">+</span><span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">ImageClickEventHandler</span><span style="color: #4444FF">(</span><span style="color: #0000FF"><strong>this</strong></span>.<span style="color: #2040a0">RegisterButton_Click</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

		<span style="color: #4444FF"><strong>}</strong></span>

		

<span style="color: #0000ff"><strong>		#endregion</strong></span>

    <span style="color: #4444FF"><strong>}</strong></span>
<span style="color: #4444FF"><strong>}</strong></span>

</pre>
